package com.top.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//判断用户是否登录
public class LoginFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        boolean login = (Boolean) req.getSession().getAttribute("login");
        if (!login){
            req.getRequestDispatcher("noLogin.jsp").forward(req,(HttpServletResponse)response);
        }
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
